********************************************************************************
* Leipziger, L, Aarslew, L, & M. Christensen
* Replication Code for "Do Group-Based Inequalities Feel More Unjust?"
* POQ, 2026
* This code: Fig SM5 & Table SM8
********************************************************************************
*********************************************************************************
clear all
frame rename default data
** Combining datasets 
use "data/IN_data_clean.dta", clear
append using "data/ZA_data_clean.dta"
append using "data/US_data_clean.dta"

lab define country_lab 1 "India" 2 "\forceindent South Africa" 3 "\forceindent US"
lab values country country_lab

lab define treat 0 "Baseline" 1 "\forceindent Vertical ineq." 2 "\forceindent Intergroup ineq."
lab values D treat

**not using within black and within white treatments
replace D=. if D>2

** Marginal effects (all)
qui reg fair_std i.D pretreat_fair i.country, rob
mat A = r(table)
est store fairness // for tables
estadd scalar ajr2 = e(r2_a)

qui reg effort_std i.D pretreat_effort i.country, rob
mat B = r(table)
est store effort // for tables
estadd scalar ajr2 = e(r2_a)

qui reg angry_std i.D i.country, rob
mat C = r(table)
est store angry // for tables
estadd scalar ajr2 = e(r2_a)


qui reg frustrated_std i.D i.country, rob
mat E = r(table)
est store frustrated // for tables
estadd scalar ajr2 = e(r2_a)

**Making table A8
esttab fairness effort angry frustrated using "output/tableSM8_tab.tex", lab nogap wide tex cells("b(fmt(3))" se(par(`"("' `")"') fmt(3)) p(par(`"["' `"]"') fmt(3)))  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(%9.3f) ///
	noobs nonotes nonumbers  ///
	stats(ajr2  N, labels("Adjusted R^2" "N") fmt(3 0)) varlabels(_cons Constant) ///
	refcat(3.D "\forceindent Intergroup ineq.")   ///
	mtitles("Fairness" "Effort" "Angry" ///
	"Frustration")  ///
	mgroups("Outcome", pattern(0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) replace
	


* Matrix 
mat D = 1,0.9,A[1,2],A[5,2],A[6,2]\			/// 
		2,1.1,A[1,3],A[5,3],A[6,3]\			///
		1,1.9,B[1,2],B[5,2],B[6,2]\			/// 
		2,2.1,B[1,3],B[5,3],B[6,3]\			///
		1,2.9,C[1,2],C[5,2],C[6,2]\			/// 
		2,3.1,C[1,3],C[5,3],C[6,3]\			///
		1,3.9,E[1,2],E[5,2],E[6,2]\			/// 
		2,4.1,E[1,3],E[5,3],E[6,3]
		
mat list D	


frame create plot1
cwf plot1		
svmat D
rename D1 treatment						// 1 = Interpersonal, 2 = Intergroup
rename D2 Xpos							// Position on X-axis
rename D3 b								// Parameter estimate (Marginal effect)
rename D4 ll							// lower confidence level
rename D5 ul							// upper confidence level


* Plot Figure A5: 
tw ///
	(rspike ll ul Xpos if treatment == 1, lc(black)) ///
	(rspike ll ul Xpos if treatment == 2, lc(black)) ///
	(scatter b Xpos if treatment == 1, msym(O) mc(black) msize(med)) ///
	(scatter b Xpos if treatment == 2, msym(O) mc(black) mfcolor(white) msize(med)) ///
	, yscale(range(-.5 .5) extend lc(none)) ytit("Effect Estimate") ///
	yline(0) ylab(-.4 -0.2 0 0.4 .2, labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	xscale(range(.5 4.5) extend) xtit("Outcome") ///
	xlab(1 "Distributive Fairness" 2 "Role of Effort" 3 "Feelings of Anger" 4 "Feelings of Frustration", labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	legend(pos(1) ring(0) order(3 "Interpersonal Inequality" 4 "Intergroup Inequality") size(vsmall)) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	scale(1.3) graphregion(m(small)) ///
	name(dist_fair, replace)
	
graph display, xsize(12) ysize(8) 
graph export "output/figure_SM5.pdf", as(pdf) replace

	
	

	
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	